<%@page import="com.bitzer.google.EmailValidator"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.google.gdata.data.extensions.Organization"%>
<%@page import="com.google.gdata.data.extensions.PostalAddress"%>
<%@page import="com.google.gdata.data.extensions.StructuredPostalAddress"%>
<%@page import="com.google.gdata.data.extensions.Email"%>
<%@page import="com.bitzer.google.Utils"%>
<%@page import="com.google.gdata.client.contacts.ContactsService"%>
<%@page import="java.io.IOException"%>
<%@page import="com.google.gdata.util.ServiceException"%>
<%@page import="com.google.gdata.data.contacts.ContactFeed"%>
<%@page import="com.google.gdata.data.contacts.ContactEntry"%>
<%@page import="java.util.List"%>
<%@page import="com.bitzer.google.Contacts"%>
<%@page import="com.bitzer.google.Constants"%>
<%
        String username = (String) session.getAttribute("username");
        String password = (String) session.getAttribute("password");

        if (username == null || username == ""
           || password == null || password == "")
            response.sendRedirect(request.getContextPath()+"/login.jsp");

       Contacts contacts = Contacts.instance();

       String firstName = request.getParameter("first_name");
       String title = request.getParameter("title");
       String notes = request.getParameter("notes");
       String lastName  = request.getParameter("last_name");
       
       String hemail    = null;
       String wemail    = null;
       String oemail    = null;

       EmailValidator validator  = new EmailValidator();

       if(validator.validate(request.getParameter("hemail"))){
            hemail = request.getParameter("hemail");
       }
       if(validator.validate(request.getParameter("wemail"))){
            wemail = request.getParameter("wemail");
       }

       if(validator.validate(request.getParameter("oemail"))){
            oemail = request.getParameter("oemail");
       }
       
       if(hemail == null && wemail == null && oemail == null)
       {
            return;
       }

       contacts.createContact(firstName, lastName, wemail, title, notes, hemail,oemail);
       
%>

